﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace IdragonetEye
{
   public class Class_winstart
    {

       public static void turnOn()
       {
           //获取程序执行路径..
           string starupPath = Application.ExecutablePath;
           //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装.
           RegistryKey loca = Registry.LocalMachine;
           RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

           try
           {
               //SetValue:存储值的名称
               run.SetValue("IdragonetEye", starupPath+" -s");
               MessageBox.Show("已启用开机运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
               loca.Close();
           }
           catch (Exception ee)
           {
               MessageBox.Show(ee.Message.ToString(), "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }
       }

       public static void turnOff()
       {
           // MessageBox.Show("没有选中");
           //获取程序执行路径..
           string starupPath = Application.ExecutablePath;
           //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装.
           RegistryKey loca = Registry.LocalMachine;
           RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

           try
           {
               //SetValue:存储值的名称
               if (run.GetValue("IdragonetEye") != null) run.DeleteValue("IdragonetEye");
               MessageBox.Show("已停止开机运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
               loca.Close();
           }
           catch (Exception ee)
           {
               MessageBox.Show(ee.Message.ToString(), "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }
       }


       public static bool Isturn()
       {

           // MessageBox.Show("没有选中");
           //获取程序执行路径..
           string starupPath = Application.ExecutablePath;
           //class Micosoft.Win32.RegistryKey. 表示Window注册表中项级节点,此类是注册表装.
           RegistryKey loca = Registry.LocalMachine;
           RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

           try
           {
               //SetValue:存储值的名称
               if (run.GetValue("IdragonetEye") == null) return false;
               loca.Close();
           }
           catch (Exception ee)
           {
               MessageBox.Show(ee.Message.ToString(), "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }

           return true;
       }
    }
}
